package com.bw.zg3park2212.point

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.bumptech.glide.Glide
import com.bw.base.entity.PointAddParam
import com.bw.base.mvvm.BaseActivity
import com.bw.zg3park2212.R
import com.bw.zg3park2212.databinding.ActivityPointAddBinding
import com.wildma.pictureselector.PictureBean
import com.wildma.pictureselector.PictureSelector

import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/PointAddActivity")
class PointAddActivity : BaseActivity<ActivityPointAddBinding,PointViewModel>() {
    var iconurl=""
    override fun intitView() {
        binding.pointPointImages.setOnClickListener {
            PictureSelector.create(this, PictureSelector.SELECT_REQUEST_CODE).selectPicture()
        }
        binding.check.setOnClickListener {
            var pointAddParam=PointAddParam()
            pointAddParam.pointImages=iconurl
            pointAddParam.pointLocation=binding.pointPointLocation.text.toString()
            pointAddParam.pointName=binding.pointPointName.text.toString()
            pointAddParam.patrolType=binding.pointPatrolType.text.toString()
            pointAddParam.patrolStandard=binding.pointPatrolStandard.text.toString()
            pointAddParam.projectId=binding.pointProjectId.text.toString()
            viewmodel.getpointadd(pointAddParam)
        }
    }

    override fun intitData() {
        viewmodel.pointaddSuccse.observe(this){
            ToastUtils.showLong("添加成功")
            finish()
        }
    }
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode==PictureSelector.SELECT_REQUEST_CODE&&resultCode==RESULT_OK){
            val bean = data!!.extras!!.get(PictureSelector.PICTURE_RESULT) as PictureBean
            Glide.with(this).load(bean.path).into(binding.pointPointImages)
            iconurl=bean.path
        }
    }
}